"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _vue = require("vue");
var _xeUtils = _interopRequireDefault(require("xe-utils"));
var _ui = require("../../ui");
var _vn = require("../../ui/src/vn");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = exports.default = (0, _vue.defineComponent)({
  name: 'VxeText',
  props: {
    status: String,
    title: [String, Number],
    icon: String,
    loading: Boolean,
    content: [String, Number],
    clickToCopy: Boolean,
    size: {
      type: String,
      default: () => (0, _ui.getConfig)().text.size || (0, _ui.getConfig)().size
    }
  },
  emits: ['click'],
  setup(props, context) {
    const {
      emit,
      slots
    } = context;
    const xID = _xeUtils.default.uniqueId();
    const {
      computeSize
    } = (0, _ui.useSize)(props);
    const refElem = (0, _vue.ref)();
    const refContentElem = (0, _vue.ref)();
    const reactData = (0, _vue.reactive)({});
    const refMaps = {
      refElem
    };
    const computeMaps = {};
    const clickIconEvent = () => {
      const {
        content,
        clickToCopy
      } = props;
      if (clickToCopy) {
        const contentEl = refContentElem.value;
        const copyVal = (contentEl ? contentEl.textContent : '') || content;
        if (copyVal) {
          if (_ui.VxeUI.clipboard.copy(copyVal)) {
            if (_ui.VxeUI.modal) {
              _ui.VxeUI.modal.message({
                content: (0, _ui.getI18n)('vxe.text.copySuccess'),
                status: 'success'
              });
            }
          } else {
            if (_ui.VxeUI.modal) {
              _ui.VxeUI.modal.message({
                content: (0, _ui.getI18n)('vxe.text.copyError'),
                status: 'error'
              });
            }
          }
        }
      }
    };
    const $xeText = {
      xID,
      props,
      context,
      reactData,
      getRefMaps: () => refMaps,
      getComputeMaps: () => computeMaps
    };
    const dispatchEvent = (type, params, evnt) => {
      emit(type, (0, _ui.createEvent)(evnt, {
        $text: $xeText
      }, params));
    };
    const textMethods = {
      dispatchEvent
    };
    const clickEvent = evnt => {
      const {
        loading
      } = props;
      if (!loading) {
        dispatchEvent('click', {}, evnt);
      }
    };
    const textPrivateMethods = {};
    Object.assign($xeText, textMethods, textPrivateMethods);
    const renderContent = () => {
      const {
        loading,
        icon,
        content,
        clickToCopy
      } = props;
      const defaultSlot = slots.default;
      const iconSlot = slots.icon;
      return [loading ? (0, _vue.h)('span', {
        class: 'vxe-text--loading'
      }, [(0, _vue.h)('i', {
        class: (0, _ui.getIcon)().TEXT_LOADING
      })]) : iconSlot || icon || clickToCopy ? (0, _vue.h)('span', {
        class: 'vxe-text--icon',
        onClick: clickIconEvent
      }, iconSlot ? (0, _vn.getSlotVNs)(iconSlot({})) : [(0, _vue.h)('i', {
        class: icon || (0, _ui.getIcon)().TEXT_COPY
      })]) : (0, _vue.createCommentVNode)(), (0, _vue.h)('span', {
        ref: refContentElem,
        class: 'vxe-text--content'
      }, defaultSlot ? defaultSlot({}) : _xeUtils.default.toValueString(content))];
    };
    const renderVN = () => {
      const {
        loading,
        status,
        title,
        clickToCopy
      } = props;
      const vSize = computeSize.value;
      return (0, _vue.h)('span', {
        ref: refElem,
        title,
        class: ['vxe-text', {
          [`size--${vSize}`]: vSize,
          [`theme--${status}`]: status,
          'is--copy': clickToCopy,
          'is--loading': loading
        }],
        onClick: clickEvent
      }, renderContent());
    };
    $xeText.renderVN = renderVN;
    return $xeText;
  },
  render() {
    return this.renderVN();
  }
});